import {
    StorageKey
} from '../common_for_guosheng/Key';
import {
    GameGSData
} from '../game_for_guosheng/GameGSData';

import {
    GameGSState
} from "../game_for_guosheng/GameGSState";

import SodaCommon from "../soda/SodaCommon";

cc.Class({
    extends: require('BaseGSScene'),

    properties: {
        label: cc.Label,
        nodLabel: cc.Node,
    },

    onLoad() {
        this.cnmd();
    },

    start() {
        F.GSPartner.sendEvent('场景', {
            '类型': 'boot'
        });
        this.allStep = 2;
        this.step = 0;
        this.index = 0;

        if (cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT_GAME) {
            SodaCommon.gameInit().then((data) => {
                GameGSData.setBestLevel(data.guan);
                GameGSState.init(data.guan);
                SodaCommon.getGameStatus().then((res) => {
                    SodaCommon.gameReviewStatus = res.value;
                    this._Fuckboot();
                    // if(SodaCommon.gameReviewStatus == 0){
                    //     this._loadSH();
                    // }else{
                    //     this._Fuckboot();

                    // }
                });
            });
        } else {
            SodaCommon.gameReviewStatus = 1;
            this._Fuckboot();
            // this._loadSH();
        }

    },

    _Fuckboot() {
        cc.game.setFrameRate(F.Config.FPS);
        GameGSData.init();
        // F.FuckAd.init();

        this._preloadFuckScene();
        this._loadFuckScene();
        return;

        let funcLoadJson = () => {
            this._loadFuckJson(() => {
                // this._loadFuckScene();
            });
        }
        // if (cc.sys.isNative) {
        //     F.Ui.openUI('PanelUpdate', { delegate: funcLoadJson.bind(this) });
        // } else {
        //     funcLoadJson();
        // }
        this.label.string = '首次启动游戏加载时间较长，\n请稍等片刻...';
        let firstLaunch = F.Data.getItem(StorageKey.FIRST_LAUNCH);
        if (firstLaunch) {
            this.label.string = '游戏加载中，请稍等片刻...';
        }
        this.node.opacity = 0;
        this.label.fontSize = 40;
        cc.tween(this.node)
            .to(1, {
                opacity: 255
            })
            .call(() => {
                this._preloadFuckScene();
            })
            .start();
    },

    _loadFuckJson(cb) {
        F.json.loadFuckAllJsons(() => {
            cb();
        });
        // F.json.addItem('test1');
        // F.json.addItem('test2');
        // F.json.startLoad(() => {
        //     console.log(F.json.getJson('test2'))
        //     cb();
        // });
    },

    _preloadFuckScene() {
        F.Game.preloadScene('SceneHome', null, () => {
            this.step++;
            this._loadFuckScene();
        });
        F.Game.preloadScene('SceneGame', null, () => {
            this.step++;
            this._loadFuckScene();
        });
    },

    _loadSH() {
        F.Game.preloadScene('ShenHe', null, () => {
            F.Game.loadScene('ShenHe');
        });
    },

    _loadFuckScene() {
        if (this.step >= this.allStep || true) {
            cc.tween(this.node)
                .delay(1)
                .to(1, {
                    opacity: 0
                })
                .call(() => {
                    F.Data.setItem(StorageKey.FIRST_LAUNCH, true);
                    F.Game.loadScene('SceneHome');
                })
                .start();
        }
    },
});